package com.enseirb.bdxmap.converter;

import java.util.List;

import com.enseirb.bdxmap.dao.ParkingMarkerDAO;
import com.enseirb.bdxmap.dao.dto.ParkingMarkerDTO;
import com.enseirb.bdxmap.exception.BdxMapException;
import com.enseirb.bdxmap.service.model.ParkingMarkerBO;

public class ParkingMarkerConverter extends AbstractMarkerConverter<ParkingMarkerDTO, ParkingMarkerBO> {
	
	private ParkingMarkerDAO parkingDAO = new ParkingMarkerDAO();
	
	@Override
	protected List<ParkingMarkerDTO> getDataFromDAO() throws BdxMapException {
		return parkingDAO.getData();
	}
	
	@Override
	protected ParkingMarkerBO newMarkerBO() {
		return new ParkingMarkerBO();
	}
	
	@Override
	protected ParkingMarkerBO setCustomFieldsBO(ParkingMarkerDTO parkingDTO, ParkingMarkerBO parkingBO) {
		parkingBO.type = parkingDTO.type;
		try {
			parkingBO.nbSpots = Integer.parseInt(parkingDTO.nbSpots);
		} catch(NumberFormatException e) {
			parkingBO.nbSpots = null;
		}
		return parkingBO;
	}
}
